//
//  FloorCardCell.m
//  QRMaster
//
//  Created by myApple on 16/5/10.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "FloorCardCell.h"

@interface FloorCardCell()
{
    UILabel * floorLabel;
    UILabel * bulidingLabel;
    UIImageView * selectImageView;
}

@end

@implementation FloorCardCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float x = 22;
    float y = 12;
    float width = ScreenWidth - x - 60;
    float height = 20;
    
    bulidingLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    bulidingLabel.font = [UIFont systemFontOfSize:15.0];
    [self.contentView addSubview:bulidingLabel];
    
    
    x += width;
    width = 100;
    floorLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    floorLabel.font = [UIFont systemFontOfSize:15.0];
    [self.contentView addSubview:floorLabel];
    
    x = UI_SCREEN_WIDTH - 38;
    y = (44 - 18)/2.0;
    width = 22;
    height = 18;
    selectImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
    selectImageView.image = [UIImage imageNamed:@"isSelect"];
    selectImageView.hidden = YES;
    [self.contentView addSubview:selectImageView];
}


-(void)setBulidingName:(NSString *)bulidingName
{
    _bulidingName = bulidingName;
    bulidingLabel.text = bulidingName;
    [self calculateWidth:bulidingName];
}

-(void)setFloorName:(NSString *)floorName
{
    _floorName = floorName;
    floorLabel.text = floorName;
}

-(void)setFloorId:(NSString *)floorId
{
    _floorId = floorId;
}

-(void)setIsSelect:(BOOL)isSelect
{
    _isSelect = isSelect;
    if (isSelect) {
        selectImageView.hidden = NO;
        bulidingLabel.textColor = UIColorFromRGB(0x7dc234);
        floorLabel.textColor = UIColorFromRGB(0x7dc234);
    }
    else
    {
        selectImageView.hidden = YES;
        bulidingLabel.textColor = UIColorFromRGB(0x333333);
        floorLabel.textColor = UIColorFromRGB(0x333333);
    }
}

#pragma mark -------重新计算位置
-(void)calculateWidth:(NSString *)str
{
     NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
    CGSize textSize = [str boundingRectWithSize:CGSizeMake(1000, 20) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    float width = textSize.width;
    bulidingLabel.frame = CGRectMake(bulidingLabel.frame.origin.x, bulidingLabel.frame.origin.y, width, bulidingLabel.frame.size.height);
    floorLabel.frame = CGRectMake(bulidingLabel.frame.origin.x + width + 10, floorLabel.frame.origin.y,UI_SCREEN_WIDTH - bulidingLabel.frame.origin.x - 10 - 35-width , floorLabel.frame.size.height);
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
